using System.Collections;
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Text;
using Ezio.Model;

//Service Route: Copy to 'Global.asax'
//  RouteTable.Routes.Add(new ServiceRoute("EntradasBodegas", new WebServiceHostFactory(), typeof(EntradasBodegasService)));
//
namespace Ezio.Service
{
    [ServiceContract]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
    [XmlSerializerFormat]
    public class EntradasBodegasService : BaseService
    {

        [WebInvoke(UriTemplate = "Create", Method = "POST")]
        public bool Create(EntradasBodegas EntradaBodega)
        {
            Provider.AddToEntradasBodegas(EntradaBodega);
            return Provider.TrySaveChanges();
        }

        [WebInvoke(UriTemplate = "CreateMassive", Method = "POST")]
        public bool Create(ArrayList ListEntradaBodega)
        {
            ListEntradaBodega.ToArray().ToList().ForEach(t => Provider.AddToEntradasBodegas((EntradasBodegas)t));
            return Provider.TrySaveChanges();
        }

        [WebInvoke(UriTemplate = "GetAll", Method = "POST")]
        public ArrayList GetAll()
        {
            return new ArrayList(Provider.EntradasBodegas.ToList());
        }

        [WebInvoke(UriTemplate = "GetById", Method = "POST")]
        public EntradasBodegas GetById(int Id)
        {
            return Provider.EntradasBodegas.First(i => i.IdEntradaBodega == Id);
        }

        [WebInvoke(UriTemplate = "Update", Method = "POST")]
        public bool Update(EntradasBodegas EntradaBodega)
        {
            EntradasBodegas miEntradaBodega = Provider.EntradasBodegas.Where(t => t.IdEntradaBodega == EntradaBodega.IdEntradaBodega).First();
            miEntradaBodega.Copy(EntradaBodega);
            return Provider.TrySaveChanges();
        }

    }
}